package com.pai4j.common.enums.community;
import com.pai4j.domain.community.vo.response.cc.CTCMenuVO;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 *
 *
 * @author: CYM-pai
 * @date: 2025/10/27 15:52
 **/
@Getter
@NoArgsConstructor
@AllArgsConstructor
public enum CTCMenuEnum {

    HOME("home", "推荐"),
    CATALOG("catalog", "目录"),
    INFORMATIONS("informations", "资讯"),
    QUESTIONS("questions", "问答"),
    EXPERIENCES("experiences", "经验"),
    RESOURCES("resources", "资料库"),
    NAVS("navs", "工具库"),
    VIDEO("video", "视频"),
    OPEN_SOURCES("openSources", "优质开源"),
    MORE("more", "更多");

    private String code;
    private String name;

    public static List<CTCMenuVO> getMenus(List<String> codes) {
        if (CollectionUtils.isEmpty(codes)) {
            return Collections.emptyList();
        }
        List<CTCMenuVO> menus = new ArrayList<>();
        if (codes.contains(CATALOG.code)) {
            menus.add(buildMenu(CATALOG));
        }
        if (codes.contains(HOME.code)) {
            menus.add(buildMenu(HOME));
        }
        if (codes.contains(INFORMATIONS.code)) {
            menus.add(buildMenu(INFORMATIONS));
        }
        if (codes.contains(VIDEO.code)) {
            menus.add(buildMenu(VIDEO));
        }
        if (codes.contains(QUESTIONS.code)) {
            menus.add(buildMenu(QUESTIONS));
        }
        if (codes.contains(EXPERIENCES.code)) {
            menus.add(buildMenu(EXPERIENCES));
        }
        if (codes.contains(RESOURCES.code)) {
            menus.add(buildMenu(RESOURCES));
        }
        if (codes.contains(NAVS.code)) {
            menus.add(buildMenu(NAVS));
        }
        if (codes.contains(OPEN_SOURCES.code)) {
            menus.add(buildMenu(OPEN_SOURCES));
        }
        if (codes.contains(MORE.code)) {
            menus.add(buildMenu(MORE));
        }
        return menus;
    }

    private static CTCMenuVO buildMenu(CTCMenuEnum menu) {
        return new CTCMenuVO(menu.code, menu.name);
    }
}
